//
//  EFReturnInfoCell.m
//  EnjogFood
//
//  Created by 王芳 on 17/6/11.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFReturnInfoCell.h"
#import "EFReturnInforItem.h"

@interface EFReturnInfoCell ()
@property (strong, nonatomic) UILabel *leftLabel;
@property (strong, nonatomic) UILabel *rightLabel;
@property (strong, nonatomic) UIView *line;

@property (strong, nonatomic) EFReturnInforItem *infoItem;
@end

@implementation EFReturnInfoCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self initUI];
    }
    return self;
}

- (void)initUI{
    [self.contentView addSubview:self.leftLabel];
    [self.contentView addSubview:self.rightLabel];
    [self.contentView addSubview:self.rightTextField];
      [self.contentView addSubview:self.line];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.line.left = 20;
    self.line.bottom = self.height;
}

- (void)setObject:(EFReturnInforItem *)item{
    self.infoItem = item;
    self.leftLabel.text = item.title;
    [self.leftLabel sizeToFit];
    self.leftLabel.left = 20;
    self.leftLabel.top = 15;
    if (item.isEdit == NO) {
        self.rightLabel.hidden = NO;
        self.rightTextField.hidden = YES;
        self.rightLabel.text = item.detail;
        [self.rightLabel sizeToFit];
        self.rightLabel.width = kScreenWidth - 2 * 20 - self.leftLabel.width;
        self.rightLabel.left = self.leftLabel.right + 4;
        self.rightLabel.top = self.leftLabel.top;
    }else{
        //快递公司和快递单号会用到这里
        self.rightLabel.hidden = YES;
        self.rightTextField.hidden = NO;
        self.rightTextField.left = self.leftLabel.right + 4;
        self.rightTextField.top = self.leftLabel.top;
    }
    
}

- (UILabel *)leftLabel{
    if (!_leftLabel) {
        _leftLabel = [[UILabel alloc] init];
        _leftLabel.font = [UIFont systemFontOfSize:13];
        _leftLabel.textColor = RGBCOLOR(0x9b9b9b);
        
    }
    return _leftLabel;
}

- (UILabel *)rightLabel{
    if (!_rightLabel) {
        _rightLabel = [[UILabel alloc] init];
        _rightLabel.font = [UIFont systemFontOfSize:13];
        _rightLabel.textColor = kBlack333;
        _rightLabel.numberOfLines = 0;
    }
    return _rightLabel;
}

- (UITextField *)rightTextField{
    if (!_rightTextField) {
        _rightTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 15)];
        _rightTextField.font = [UIFont systemFontOfSize:13];
        _rightTextField.placeholder = @"请填写";
    }
    return _rightTextField;
}

+ (CGFloat)returnInfoCellHeight:(EFReturnInforItem *)item{
    UILabel *leftTempLabel = [[UILabel alloc] init];
    leftTempLabel.font = [UIFont systemFontOfSize:13];
    leftTempLabel.text = item.title;
    [leftTempLabel sizeToFit];
    
    if (item.detail == nil || item.detail.length ==0) {
        return 42;
    }
    UILabel *tempLabel = [[UILabel alloc] init];
    tempLabel.font = [UIFont systemFontOfSize:13];
    tempLabel.numberOfLines = 0;
    tempLabel.text = item.detail;
    tempLabel.width =  kScreenWidth - 2 * 20 - leftTempLabel.width;
    [tempLabel sizeToFit];
    
    return tempLabel.height + 2*15;
    
}

- (UIView *)line{
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 2*20, 1)];
        _line.backgroundColor = RGBCOLOR(0xececec);
    }
    return _line;
}

@end
